/**
 * Created by ${PRODUCT_NAME}.
 * User: skylerparr
 * Date: 12/12/10
 * Time: 8:51 AM
 * To change this template use File | Settings | File Templates.
 */
package com.thoughtorigin.injector {
import com.thoughtorigin.injector.mocks.SampleInject;
import com.thoughtorigin.flux.Flux;

import com.thoughtorigin.flux.asflux.ActionscriptFlux;
import com.thoughtorigin.reflect.PropertyAccess;
import com.thoughtorigin.reflect.PropertyMetaDataItem;

import org.flexunit.asserts.assertEquals;
import org.flexunit.asserts.fail;
import org.mockito.integrations.atLeast;
import org.mockito.integrations.given;
import org.mockito.integrations.mock;
import org.mockito.integrations.verify;


[RunWith("org.mockito.integrations.flexunit4.MockitoClassRunner")]
[Mock(type="com.thoughtorigin.flux.Flux")]
public class SimpleInjectorTest {

    private var _injector: SimpleInjector;
    private var _ioc: Flux;

    [Before]
    public function setup(): void {
        _ioc = mock(Flux);
        _injector = new SimpleInjector(_ioc);
        SimpleInjector.flux = _ioc;
    }

    [After]
    public function tearDown(): void {
        _injector = null;
    }

    [Test]
    public function shouldInjectPropertiesIntoPropertyMethodBasedOnMethodName(): void {
        var callback: Function = function(): void {
            assertEquals(obj, s.something);
        }
        var obj: Object = new Object();
        given(_ioc.getProperty("something")).willReturn(obj);
        var s: SampleInject = new SampleInject();
        _injector.metaData = new PropertyMetaDataItem("Inject", [], "something", PropertyAccess.READ_WRITE);
        _injector.inject(s, callback);

        verify(atLeast(1)).that(_ioc.getProperty("something"));
    }

    [Test]
    public function shouldInjectPropertiesIntoPropertyMethodBasedOnMetaDataArg(): void {
        var callback: Function = function(): void {
            assertEquals(obj, s.somethingElse);
        }
        var propertyName: String = "fire";
        var obj: Object = new Object();
        given(_ioc.getProperty(propertyName)).willReturn(obj);
        var s: SampleInject = new SampleInject();
        _injector.metaData = new PropertyMetaDataItem("Inject", [propertyName], "somethingElse", PropertyAccess.READ_WRITE);
        _injector.inject(s, callback);

        verify(atLeast(1)).that(_ioc.getProperty(propertyName));
    }
}
}
